package org.example.day20240905.app;

import org.example.day20240905.model.Article;
import org.example.day20240905.model.User;
import org.example.day20240905.util.GlobalInput;
import org.example.day20240905.view.ArticleView;
import org.example.day20240905.view.RegisterView;
import org.example.day20240905.view.UserView;

import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = GlobalInput.getScanner();
        boolean isRunning = true;
        while (isRunning){
            System.out.println("--------realword---------");
            if(User.loadUser == null){
                System.out.println("1. 用户注册");
                System.out.println("2. 用户登陆");
                System.out.println("3. 查看文章");
                System.out.println("0. 退出系统");
            }else {
                System.out.println("1. 发表文章");
                System.out.println("2. 修改个人信息");
                System.out.println("3. 查看文章");
                System.out.println("4. 注销");
                System.out.println("0. 退出系统");
            }

            int cmd = scanner.nextInt();
            scanner.nextLine();
                switch (cmd){
                    case 0:{
                        isRunning = false;
                        break;
                    }
                    case 1:{
                        if(User.loadUser == null){
                            UserView userView = new UserView();
                            boolean result = userView.registerUser();
                            if(result){
                                System.out.println("注册成功");
                            }else {
                                System.out.println("注册失败");
                            }
                        }else{
                            ArticleView articleView = new ArticleView();
                            articleView.createArticle();
                        }
                        break;
                    }
                    case 2:{
                        if(User.loadUser == null){
                            RegisterView registerView = new RegisterView();
                            User.loadUser = registerView.register();
                            if(User.loadUser != null){
                                System.out.println("登陆成功");
                            }else {
                                System.out.println("登陆失败");
                            }
                        }
                        break;
                    }
                    case 3:{
                        ArticleView articleView = new ArticleView();
                        Map<String,List<Article>> article = articleView.checkArticle();
                        System.out.println("输入数字查看对应id的文章详情：");
                        scanner = GlobalInput.getScanner();
                        int num = scanner.nextInt();
                        ArticleView.viewArticle(num,article);

                        break;
                    }
                    case 4:{
                        User.loadUser = null;
                        System.out.println("注销成功");
                        break;
                    }
                    default:
                        break;
                }
            }
        System.out.println("byebye");
        scanner.close();
    }
}
